package com.cheng.operation.impl;

import com.cheng.common.exception.CommonException;
import com.cheng.common.utils.IdUtil;
import com.cheng.data.entity.LoginLogInfoEntity;
import com.cheng.data.vo.LoginLogInfoVO;
import com.cheng.operation.LoginLogInfoOperation;
import com.cheng.service.LoginLogInfoService;
import com.cheng.service.impl.LoginLogInfoServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: ChengJW
 * @date: 2021/12/26 10:55
 * @version: 1.0
 * @description: 登录日志处理类
 */
@Service
public class LoginLogInfoOperationImpl implements LoginLogInfoOperation {

    private final static Logger log = LoggerFactory.getLogger(LoginLogInfoOperationImpl.class);

    @Autowired
    private LoginLogInfoService loginLogInfoService;

    /**
    * @author: ChengJW
    * @params: [loginLogInfoVO]
    * @return: void
    * @date: 2021/12/26
    * @description: 插入登录日志信息
    */
    @Override
    public void insertLoginLogInfo(LoginLogInfoVO loginLogInfoVO) throws CommonException {
        if (loginLogInfoVO == null){
            log.error("登录日志信息为空，无法进行下一步操作");
            throw new CommonException("CJW202111010058","LoginLogInfoOperationImpl","insertLoginLogInfo");
        }
        LoginLogInfoEntity entity = new LoginLogInfoEntity();
        BeanUtils.copyProperties(loginLogInfoVO,entity);
        entity.setLlId(IdUtil.getLoginId());
        entity.setLlDt(new Date());
        entity.setStDt(new Date());
        entity.setUtDt(new Date());
        loginLogInfoService.insertLoginLogInfo(entity);

    }
}
